package com.yange.accountbook.ui.adapter

import android.widget.ImageView
import android.widget.RelativeLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yange.accountbook.R
import com.yange.accountbook.entity.IconEntity
import com.yange.accountbook.utils.image.loadCircleImg

class IconAdapter :
    BaseQuickAdapter<IconEntity, BaseViewHolder>(R.layout.books_icon_item_layout) {
    var checkedPosition = -1
    override fun convert(holder: BaseViewHolder, item: IconEntity) {
        var image = holder.getView<ImageView>(R.id.iv_icon)
        var layout = holder.getView<RelativeLayout>(R.id.layout_icon)
        context.loadCircleImg(image, item.icon)
        holder.setText(R.id.tv_title, item.name)
        if (holder.layoutPosition == checkedPosition) {
            //设置为选中
            layout.setBackgroundResource(R.drawable.round_checked)
        } else {
            layout.setBackgroundResource(R.drawable.round_normal)
        }
    }

    fun setChecked(int: Int) {
        checkedPosition = int
        notifyDataSetChanged()
    }
}